/**
 *    @file       workthread.cpp
 *
 *    @brief      
 *    @details
 *
 *    @version    1.0
 *    @date       02/12/2014 09:48:55 AM
 *
 *    @author     Theophilus (), wangtf418@gmail.com 
 */
#include "workthread.h"
#include "server.h"

workthread::workthread(bf_uint32_t type, bf_uint32_t size, bf_uint32_t index, const comargs *args)
	: m_thd_type(type), m_grp_size(size), m_thd_index(index), m_args(NULL)
{
	if (args)
	{
		m_args = args->clone();
	}
}

workthread::~workthread()
{
	if (m_args)
	{
		delete m_args;
	}
}

bf_int_t workthread::put_msg(message *msg)
{
	if (msg)
	{
		delete msg;
	}
	return BF_OK;
}

bf_size_t workthread::get_msgq_len()
{
	return 0;
}

void workthread::send_msg(bf_int32_t type, bf_uint32_t index, bf_uint64_t taskid, bf_uint32_t msgtype, msgbody *body, bf_uint64_t src_taskid /* = DEFAULT_TASKID */)
{
	msghead head;
	head.m_src_thd_type = m_thd_type;
	head.m_src_thd_index = m_thd_index;
	head.m_src_tsk_id = src_taskid;

	head.m_thd_type = type;
	head.m_thd_index = index;
	head.m_tsk_id = taskid;

	head.m_msgtype = msgtype;

	message *msg = new message(head, body);
	server::get()->put_msg(msg);
}

bf_int_t workthread::proc_msg(message *msg)
{
	return BF_OK;
}

bf_int_t workthread::add_timer(interval_timer &itimer)
{
	return timer::add_timer(this, itimer);
}

bf_int_t workthread::add_timer(point_timer &ptimer)
{
	return timer::add_timer(this, ptimer);
}
